#include <REGX52.H>
#include "I2C.h"

#define AT24C02_ADDRESS 0xA0

/**
  * @brief  AT24C02写入一个字节数据
  * @param  WordAddress字节地址，Data字节数据
  * @retval 无
  */
void AT24C02_WriteByte(unsigned char WordAddress,Data)
{
	I2C_Start();
	I2C_SendByte(AT24C02_ADDRESS);
	I2C_ReceiveACK();
	I2C_SendByte(WordAddress);
	I2C_ReceiveACK();
	I2C_SendByte(Data);
	I2C_ReceiveACK();
	I2C_Stop();
}

/**
  * @brief  AT24C02读取一个字节数据
  * @param  WordAddress字节地址
  * @retval Data字节数据
  */
unsigned char AT24C02_ReadByte(unsigned char WordAddress)
{
	unsigned char Data;
	I2C_Start();
	I2C_SendByte(AT24C02_ADDRESS);
	I2C_ReceiveACK();
	I2C_SendByte(WordAddress);
	I2C_ReceiveACK();
	I2C_Start();
	I2C_SendByte(AT24C02_ADDRESS|0x01);
	I2C_ReceiveACK();
	Data=I2C_ReceiveByte();
	I2C_SendACK(1);
	return Data;
}